package com.boat.framework.common.monitor.event;

import com.boat.framework.base.api.Response;
import com.boat.framework.common.util.ServletUtils;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
 * api调用出错
 * 
 * 羽嘉框架已自动埋点，业务系统无需开发
 * 
 * @author 周江
 *
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class ControllerCallFailed extends BaseMonitorEvent {

	/**
	 * 原始异常类型
	 */
	private String exceptionType;
	/**
	 * 原始异常消息
	 */
	private String exceptionMsg;
	/**
	 * 转换后的错误类型
	 */
	private String errCode;
	/**
	 * 转换后的错误消息
	 */
	private String errMsg;

	/**
	 * 错误描述
	 */
	private String remark;

	public ControllerCallFailed() {
		super();
	}

	public ControllerCallFailed(Throwable ex, Response<Void> response) {
		super();
		if (ServletUtils.getRequest() != null) {
			setName(ServletUtils.getRequest().getRequestURI());
		}		
		
		//设置扩展参数
		setExceptionType(
				ex.getCause() != null ? ex.getCause().getClass().getSimpleName() : ex.getClass().getSimpleName());
		setExceptionMsg(ex.getMessage());
		setErrCode(response.getCode());
		setErrMsg(response.getMessage());
		setRemark("Controller执行出错");
	}

}
